﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace Tools
{
    public class HtmlToJsonString
    {
        public void Run(string inputFolder, string outputFolder)
        {
            var filesNames = Directory.GetFiles(inputFolder);
            foreach (var filesName in filesNames)
            {
                Convert(filesName, Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(filesName) + ".json"));
            }
        }

        private void Convert(string input, string output)
        {
            using (var readStream = new FileStream(input, FileMode.Open))
            {
                string html = string.Empty;

                using (var reader = new StreamReader(readStream))
                {
                    html = reader.ReadToEnd();
                }

                string result = JsonConvert.SerializeObject(html);

                using (var writeStream = new FileStream(output, FileMode.OpenOrCreate))
                {
                    using (var writer = new StreamWriter(writeStream))
                    {
                        writer.WriteLine(result);
                    }
                }
            }
        }
    }
}
